import 'dart:ui';

import 'package:demo/common/mixin/notifier/safe_value_notifier.dart';

import 'state_model.dart';

/// 缺省页控制器
class StateCtrl extends SafeValueNotifier<StateModel> {
  VoidCallback? onRefresh;

  StateCtrl({StateModel initState = const StateModel(StateEnum.content),this.onRefresh}) : super(initState);

  ///显示内容
  void showContent({Object? obj}) {
    value = StateModel(StateEnum.content, obj: obj);
  }

  ///空数据
  void showEmpty({Object? obj}) {
    value = StateModel(StateEnum.empty, obj: obj);
  }

  ///加载失败
  void showError({Object? obj}) {
    value = StateModel(StateEnum.error, obj: obj);
  }

  ///加载中
  void showLoading({Object? obj}) {
    value = StateModel(StateEnum.loading, obj: obj);
    onRefresh?.call();
  }

  /// 静默刷新, 仅触发onRefresh, 不会改变缺省页状态
  void refresh() {
    onRefresh?.call();
  }
}
